<!DOCTYPE html>
<html class="x-admin-sm">

{include file="common/static" /}
{include file="common/resources" /}

<style>
    a{
        text-decoration:none;
    }
    a:hover{
        text-decoration:none;
    }
</style>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a>
                    <cite>酒店设置</cite>
                </a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                    <div class="layui-card-body ">
                    <form action="" method="post">
                    <table class="layui-table layui-form">

                        <tbody>
                        <tr>
                            <td>
                                <!--图片上传开始-->
                                <input type="file" id="photoFile" style="display: none;" onchange="upload()">

                                <img id="preview_photo" src="{$list.logo}" width="100px" height="100px">
                                <a href="javascript:void(0)" onclick="uploadPhoto()" class="layui-btn layui-btn-sm layui-btn-warm ">选择图片</a>
                                <!--图片上传end-->
                            </td>
                            <button class="layui-btn" type="submit">
                                <i class="layui-icon"></i>保存基本设置
                            </button>
                        </tr>
                        <tr>
                            <td>
                                <div class="layui-form-item">
                                    <label for="username" class="layui-form-label">
                                        <span class="x-red">酒店名称</span>
                                    </label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="hotel_name" name="hotel_name" required="" lay-verify="required"
                                               autocomplete="off" class="layui-input" value="{$list.hotel_name}">
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="layui-form-item">
                                    <label for="username" class="layui-form-label">
                                        <span class="x-red">酒店电话</span>
                                    </label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="tel" name="tel" required="" lay-verify="required"
                                               autocomplete="off" class="layui-input" value="{$list.tel}">
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="layui-form-item">
                                    <label for="username" class="layui-form-label">
                                        <span class="x-red">酒店设施</span>
                                    </label>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            {volist name="facilities" id="vo"}
                                                <input type="checkbox" name="facilities[]" value="{$vo.name}" title="{$vo.name}" {if in_array($vo['name'],explode(",", $list['facilities'])) }checked {/if}  >
                                            {/volist}
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="layui-form-item">
                                    <label for="username" class="layui-form-label">
                                        <span class="x-red">酒店地址</span>
                                    </label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="address" name="address" required="" lay-verify="required"
                                               autocomplete="off" class="layui-input" value="{$list.address}">
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="layui-form-item">
                                    <label for="username" class="layui-form-label">
                                        <span class="x-red">酒店介绍</span>
                                    </label>

                                    <div class="layui-input-block">
                                        <textarea name="text" placeholder="酒店介绍" class="layui-textarea" id="text">{$list.text}</textarea>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    </form>
                </div>

                <button type="button" class="layui-btn" onclick="uploadimg()">添加酒店演示图</button>
                <input type="file" id="imgFile" style="display: none;" onchange="hotel()">

                <div class="layui-carousel" id="test1">
                    <div carousel-item>
                        {volist name="hotel_img" id="img"}
                        <div>
                            <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="remove_img({$img.id})"
                                style="float: right;margin-bottom: -60px;position:relative;z-index:777;" >
                                移除图片
                            </button>
<!--                            <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="set_img({$img.id})"
                                    style="float: left;margin-bottom: -60px;position:relative;z-index:777;" >
                               设为封面图
                            </button>-->
                            <img src="{$img.src}" width="100%" >
                        </div>
                        {/volist}
                    </div>
                </div>


            </div>
        </div>
    </div>
</div>
</body>

<script>
    layui.use(
            ['laydate', 'form']
    );

    layui.use('carousel', function(){
        var carousel = layui.carousel;
        //建造实例
        carousel.render({
            elem: '#test1'
            ,width: '100%' //设置容器宽度
            ,arrow: 'always' //始终显示箭头
            ,height:"800px"
            //,anim: 'updown' //切换动画方式
        });
    });

    function uploadPhoto() {
        $("#photoFile").click();
    }

    /**
     * 上传图片
     */
    function upload() {
        if ($("#photoFile").val() == '') {
            return;
        }
        var formData = new FormData();
        formData.append('photo', document.getElementById('photoFile').files[0]);
        $.ajax({
            url:"{:url('home/systems/uploadPhoto')}",
            type:"post",
            data: formData,
            contentType: false,
            processData: false,
            success: function(data) {
                if (data.type == "success") {
//                    $("#preview_photo").attr("src", data.filepath+data.filename);
                    $("#preview_photo").attr("src", data.filepath);
                    $("#productImg").val(data.filename);
                } else {
                    alert(data.msg);
                }
            },
            error:function(data) {
                alert("上传失败")
            }
        });
    }
/*-------上传酒店环境图*/
    function uploadimg() {
        $("#imgFile").click();
    }

    function hotel(){
        if ($("#imgFile").val() == '') {
            return;
        }

        var formData = new FormData();
        formData.append('img', document.getElementById('imgFile').files[0]);
        $.ajax({
            url:"{:url('home/systems/hotel_img')}",
            type:"post",
            data: formData,
            contentType: false,
            processData: false,
            success: function(data) {
                if (data.type == "success") {
                    location.reload();
                }
            },
            error:function(data) {
                alert("上传失败")
            }
        });
    }

    /*
    * 删除酒店场景图片
    * */
    function remove_img(id){
        $.ajax({
            type:"post",
            url: "{:url('home/systems/remove_img')}",
            data: {
                id:id
            },
            success: function(data){
                console.log(data);
                toastr.error(data.msg);
                if(data.code == 100){
                    setTimeout(function () {
                        location.reload();
                    },1000);
                }
            }});
    }

    /*
    * 设置酒店封面图
    * */
    function set_img(id){
        $.ajax({
            type:"post",
            url: "{:url('home/systems/set_img')}",
            data: {
                id:id
            },
            success: function(data){
                console.log(data);
                toastr.error(data.msg);
                if(data.code == 100){
                    setTimeout(function () {
                        location.reload();
                    },1000);
                }
            }});
    }
</script>


</html>